package com.qg.rta.support.lifecycle;

import cn.hutool.core.lang.ClassScanner;
import com.google.common.collect.Maps;

import com.qg.rta.annnotions.ProductType;
import com.qg.rta.context.HandlerReportContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class HandlerProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        //产品测注入
        Map<String,Class> reportHandlerMap= Maps.newHashMap();
        ClassScanner.scanPackageByAnnotation("com.qg.rta.support.channel", ProductType.class).forEach(clazz -> {
            String type=clazz.getAnnotation(ProductType.class).value();
            reportHandlerMap.put(type,clazz);
        });
        HandlerReportContext handlerReportContext=new HandlerReportContext(reportHandlerMap);
        beanFactory.registerSingleton(HandlerReportContext.class.getName(),handlerReportContext);




    }
}
